<?php
include_once 'DBConn.php';
include_once $_SERVER ['DOCUMENT_ROOT'] . '/ad/sys/com/model/util/plog/classes/plog.php';
abstract class BaseDAO {
	
	protected $dbConn;
	protected $log;
	
	function __construct() {
		$this->dbConn = new DBConn ();
		Plog::set_config ( include $_SERVER ['DOCUMENT_ROOT'] . '/ad/sys/com/model/util/plog/config.php' );
	}
	
	function toArray($result, $isObj = true) {
		$row_set = array ();
		if ($isObj) {
			while ( $row = @mysql_fetch_object ( $result ) ) {
				$row_set [] = $row;
			}
		} else {
			while ( $row = @mysql_fetch_row ( $result ) ) {
				$row_set [] = $row;
			}
		}
		@mysql_free_result ( $result );
		return $row_set;
	}
	
	 
	
	function genInserSQL($tableName, $arr) {
		$sql = "insert into $tableName ";
		$field = "";
		$val = "";
		foreach ( $arr as $key => $value ) {
			if ("Pid" != $key) {
				$field .= "$key,";
				
				if (is_string ( $value )) {
					$val .= "'" . $value . "',";
				} else {
					$val .= $value . ",";
				}
			}
		}
		return $sql .= "(" . substr ( $field, 0, strlen ( $field ) - 1 ) . ") values (" . substr ( $val, 0, strlen ( $val ) - 1 ) . ")";
	}
	
	protected function open() {
		$this->dbConn->open ();
	}
	
	protected function close() {
		$this->dbConn->close ();
	}
	
	function __destruct() {
		$this->close ();
	}
}
?>